﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace CTEA_INDIA
{
    public partial class Audition_Sheet1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (!IsPostBack)
            {
                if (Session["UserID"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
            }

            BAL.Customers.PopulateLocation(ref ddlLocationpo);
            BAL.Customers.PopulateLocation(ref cmbEdtLocationpo);
            populateAudtionpo();

            for (int i = 1; i <= 12; i++)
            {
                cmbEdtHrpo.Items.Add(i.ToString());

            }

            cmbEdtMinpo.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbEdtMinpo.Items.Add(i.ToString());
            }



            for (int i = 1; i <= 12; i++)
            {
                cmbDelHrpo.Items.Add(i.ToString());

            }

            cmbDelMinpo.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbDelMinpo.Items.Add(i.ToString());
            }

        }

        protected void btnSubmit_Clickpo(object sender, EventArgs e)
        {
            DateTime AuditoinDate =Convert.ToDateTime( txtAudtionDatepo.Text);
            string ProductionName = txtProductionNamepo.Text;
            string TitleProduction = txtTitleOfProductionpo.Text;
            string TypeProduction = ddltypeOfProductionpo.Text;
            string CastingDirectName = txtCastingDirectorpo.Text;
            string ContNo = txtContactNopo.Text;
            string Address = ddlLocationpo.Text;
            string hr = cmbDelHrpo.Text;
            string min = cmbDelMinpo.Text;
            string ampm = cmbDelAmPmpo.Text;
            BAL.Customers.AuditionSheetDetails(AuditoinDate ,ProductionName ,TitleProduction ,TypeProduction,CastingDirectName ,ContNo,Address , hr , min , ampm);

           

            populateAudtionpo();
            txtTitleOfProductionpo.Text = "";
            txtCastingDirectorpo.Text = "";
            txtContactNopo.Text = "";
            txtAudtionDatepo.Text = "";
            ddltypeOfProductionpo.SelectedIndex = 0;
            txtProductionNamepo.Text = "";

        }

        public void clearpo()
            {

            txtTitleOfProductionpo.Text = "";
            txtCastingDirectorpo.Text = "";
            txtContactNopo.Text = "";
            txtAudtionDatepo.Text = "";
            ddltypeOfProductionpo.SelectedIndex = 0;
            txtProductionNamepo.Text = "";


            }      

      
        public void populateAudtionpo()
        {

            DataSet ds = BAL.Customers.ViewAllAudtionSheetDetails();
            grdAudtionSheetpo.DataSource = ds;
            grdAudtionSheetpo.DataBind();

        }

        protected void ShowInsertAritstpo(object sender, CommandEventArgs e)
        {

            LinkButton lnkAudiID = (LinkButton)sender;
            GridViewRow row = (GridViewRow)lnkAudiID.Parent.Parent;
            GridViewRow grdAudiSheet = (GridViewRow)(lnkAudiID.Parent.Parent);
            int AudiID = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
          
           

            Response.Redirect("Audition_Artist.aspx?AudiID=" + AudiID );

          
        }


        protected void btnSearch_Clickpo(object sender, EventArgs e)
        {

        }

        protected void lnkEdit_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            string[] Details = BAL.Customers.GetAuditionSheetById(Cid);
            ViewState["AudtionID"] = Cid.ToString();

            txtEdtAudDatepo.Text =DateTime.Parse( Details[1]).ToShortDateString();
            txtEdtProdNamepo.Text = Details[2];
            txtEdtTOPpo.Text = Details[3];
            cmbEdtTypeOPpo.SelectedValue = Details[4];
            txtEdtCDNpo.Text = Details[5];
            txtEdtContactpo.Text = Details[6];
            cmbEdtLocationpo.SelectedValue = Details[7];
            
            
            cmbEdtHrpo.SelectedValue = Details[8];
            cmbEdtMinpo.SelectedValue = Details[9];
            cmbEdtAmPmpo.SelectedValue = Details[10];

            LnkEditPopUppo.Show();
        }

        protected void lnkDelete_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            BAL.Customers.DeleteAuditionSheetDetailById(Cid);
            populateAudtionpo();
        }

        protected void updatepo(object sender, EventArgs e)
        {


            DateTime AuditoinDate = Convert.ToDateTime( txtEdtAudDatepo.Text);
            string ProductionName =  txtEdtProdNamepo.Text;
            string TitleProduction =  txtEdtTOPpo.Text ;
            string TypeProduction = cmbEdtTypeOPpo.Text;
            string CastingDirectName = txtEdtCDNpo.Text;
            string ContNo = txtEdtContactpo.Text;
            string Address = cmbEdtLocationpo.SelectedValue;
            string hr = cmbEdtHrpo.Text;
            string min = cmbEdtMinpo.Text;
            string ampm = cmbEdtAmPmpo.Text;

            string AudtionID = ViewState["AudtionID"].ToString();
            BAL.Customers.UpdateAuditionSheetDetails(AudtionID , AuditoinDate, ProductionName, TitleProduction, TypeProduction, CastingDirectName, ContNo, Address , hr , min , ampm);

            populateAudtionpo();

        }

        protected void lnkView_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;
            // int locationID = Convert.ToInt32(ddlLocation.SelectedValue);
            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            string[] Details = BAL.Customers.GetAuditionSheetById(Cid);

            lblDateOfAudpo.Text= Details[1];
            lblProdNamepo.Text = Details[2];
            lblTOPpo.Text = Details[3];
            lblTypeOPpo.Text = Details[4];
            lblCDNpo.Text = Details[5];
            lblContactpo.Text = Details[6];
            lblLocationpo.Text = Details[7];
            lblViewTimepo.Text = Details[8] + ":" + Details[9] + ":" + Details[10] ;
            lnkView_ModalPopupExtenderpo.Show();

            //document.getElementById("totalDaystd").innerHTML = "<asp:TextBox ID=\"txtDaysText\" runat=\"server\" ReadOnly=\"True\" Text=\""+ days +"\"></asp:TextBox>";

        }

      

    }
}